﻿namespace Licens
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Base;
    using DevExpress.XtraGrid.Views.Grid;
    using Licens.Class;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class frmcapkey : XtraForm
    {
        private SimpleButton btnketthuc;
        private SimpleButton btnluu;
        private SimpleButton btnmoi;
        private CheckBox chkkhongthoihan;
        private IContainer components = null;
        private DateEdit datengaysudung;
        private GridControl gridControl;
        private GridColumn gridkhongthoihan;
        private GridColumn gridmadangky;
        private GridColumn gridmaso;
        private GridColumn gridngaybatdau;
        private GridColumn gridngaycap;
        private GridColumn gridsongay;
        private GridColumn gridsortdate;
        private GridView gridView1;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label label4;
        private ImageList navbarImageList;
        private ImageList navbarImageListLarge;
        private NumericUpDown numsongay;
        private RepositoryItemCheckEdit repositoryItemCheckEdit1;
        private TextEdit txtkeys;
        private TextEdit txtmaso;

        public frmcapkey()
        {
            this.InitializeComponent();
        }

        private void btnketthuc_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnluu_Click(object sender, EventArgs e)
        {
            if (this.txtmaso.Text == "")
            {
                MessageBox.Show("Nhập m\x00e3 số.", "Th\x00f4ng b\x00e1o");
            }
            else
            {
                Access access = new Access();
                if (!access.f_kiemtra_maso(this.txtmaso.Text))
                {
                    MessageBox.Show("M\x00e3 số kh\x00f4ng hợp lệ.", "Th\x00f4ng b\x00e1o");
                }
                else
                {
                    this.txtkeys.Text = access.f_get_capkey(Convert.ToInt16(this.numsongay.Value), this.datengaysudung.Text, this.chkkhongthoihan.Checked);
                    access.f_save_madangkyds(this.txtmaso.Text, this.txtkeys.Text);
                    this.gridControl.DataSource = access.f_load_madangkyds();
                }
            }
        }

        private void btnmoi_Click(object sender, EventArgs e)
        {
            this.txtkeys.Text = this.txtmaso.Text = "";
            this.numsongay.Value = 1M;
            this.datengaysudung.EditValue = DateTime.Now;
            this.chkkhongthoihan.Checked = false;
            this.txtmaso.Focus();
        }

        private void chkkhongthoihan_CheckedChanged(object sender, EventArgs e)
        {
            this.numsongay.Enabled = !this.chkkhongthoihan.Checked;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.gridControl.DataSource = new Access().f_load_madangkyds();
        }

        private void frmcapkey_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmcapkey));
            this.navbarImageListLarge = new System.Windows.Forms.ImageList(this.components);
            this.navbarImageList = new System.Windows.Forms.ImageList(this.components);
            this.gridControl = new DevExpress.XtraGrid.GridControl();
            this.gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView();
            this.gridmaso = new DevExpress.XtraGrid.Columns.GridColumn();
            this.gridmadangky = new DevExpress.XtraGrid.Columns.GridColumn();
            this.gridngaybatdau = new DevExpress.XtraGrid.Columns.GridColumn();
            this.gridsongay = new DevExpress.XtraGrid.Columns.GridColumn();
            this.gridkhongthoihan = new DevExpress.XtraGrid.Columns.GridColumn();
            this.repositoryItemCheckEdit1 = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
            this.gridngaycap = new DevExpress.XtraGrid.Columns.GridColumn();
            this.gridsortdate = new DevExpress.XtraGrid.Columns.GridColumn();
            this.label1 = new System.Windows.Forms.Label();
            this.txtmaso = new DevExpress.XtraEditors.TextEdit();
            this.label2 = new System.Windows.Forms.Label();
            this.datengaysudung = new DevExpress.XtraEditors.DateEdit();
            this.numsongay = new System.Windows.Forms.NumericUpDown();
            this.label3 = new System.Windows.Forms.Label();
            this.chkkhongthoihan = new System.Windows.Forms.CheckBox();
            this.label4 = new System.Windows.Forms.Label();
            this.txtkeys = new DevExpress.XtraEditors.TextEdit();
            this.btnketthuc = new DevExpress.XtraEditors.SimpleButton();
            this.btnmoi = new DevExpress.XtraEditors.SimpleButton();
            this.btnluu = new DevExpress.XtraEditors.SimpleButton();
            ((System.ComponentModel.ISupportInitialize)(this.gridControl)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.gridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.repositoryItemCheckEdit1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.txtmaso.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.datengaysudung.Properties.VistaTimeProperties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.datengaysudung.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.numsongay)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.txtkeys.Properties)).BeginInit();
            this.SuspendLayout();
            // 
            // navbarImageListLarge
            // 
            this.navbarImageListLarge.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.navbarImageListLarge.ImageSize = new System.Drawing.Size(16, 16);
            this.navbarImageListLarge.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // navbarImageList
            // 
            this.navbarImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.navbarImageList.ImageSize = new System.Drawing.Size(16, 16);
            this.navbarImageList.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // gridControl
            // 
            this.gridControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.gridControl.Location = new System.Drawing.Point(1, 1);
            this.gridControl.MainView = this.gridView1;
            this.gridControl.Name = "gridControl";
            this.gridControl.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
            this.repositoryItemCheckEdit1});
            this.gridControl.Size = new System.Drawing.Size(1007, 616);
            this.gridControl.TabIndex = 1;
            this.gridControl.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] {
            this.gridView1});
            // 
            // gridView1
            // 
            this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Simple;
            this.gridView1.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
            this.gridmaso,
            this.gridmadangky,
            this.gridngaybatdau,
            this.gridsongay,
            this.gridkhongthoihan,
            this.gridngaycap,
            this.gridsortdate});
            this.gridView1.GridControl = this.gridControl;
            this.gridView1.Name = "gridView1";
            // 
            // gridmaso
            // 
            this.gridmaso.Caption = "Mã số";
            this.gridmaso.FieldName = "1";
            this.gridmaso.Name = "gridmaso";
            this.gridmaso.OptionsColumn.AllowEdit = false;
            this.gridmaso.OptionsColumn.ReadOnly = true;
            this.gridmaso.Visible = true;
            this.gridmaso.VisibleIndex = 0;
            this.gridmaso.Width = 170;
            // 
            // gridmadangky
            // 
            this.gridmadangky.Caption = "Key";
            this.gridmadangky.FieldName = "2";
            this.gridmadangky.Name = "gridmadangky";
            this.gridmadangky.OptionsColumn.ReadOnly = true;
            this.gridmadangky.Visible = true;
            this.gridmadangky.VisibleIndex = 1;
            this.gridmadangky.Width = 185;
            // 
            // gridngaybatdau
            // 
            this.gridngaybatdau.Caption = "Ngày sử dụng";
            this.gridngaybatdau.FieldName = "3";
            this.gridngaybatdau.Name = "gridngaybatdau";
            this.gridngaybatdau.OptionsColumn.AllowEdit = false;
            this.gridngaybatdau.OptionsColumn.ReadOnly = true;
            this.gridngaybatdau.Visible = true;
            this.gridngaybatdau.VisibleIndex = 2;
            this.gridngaybatdau.Width = 103;
            // 
            // gridsongay
            // 
            this.gridsongay.Caption = "Số ngày";
            this.gridsongay.FieldName = "4";
            this.gridsongay.Name = "gridsongay";
            this.gridsongay.OptionsColumn.AllowEdit = false;
            this.gridsongay.OptionsColumn.ReadOnly = true;
            this.gridsongay.Visible = true;
            this.gridsongay.VisibleIndex = 3;
            this.gridsongay.Width = 54;
            // 
            // gridkhongthoihan
            // 
            this.gridkhongthoihan.Caption = "Không thời hạn";
            this.gridkhongthoihan.ColumnEdit = this.repositoryItemCheckEdit1;
            this.gridkhongthoihan.FieldName = "5";
            this.gridkhongthoihan.Name = "gridkhongthoihan";
            this.gridkhongthoihan.OptionsColumn.AllowEdit = false;
            this.gridkhongthoihan.OptionsColumn.ReadOnly = true;
            this.gridkhongthoihan.OptionsFilter.AutoFilterCondition = DevExpress.XtraGrid.Columns.AutoFilterCondition.Contains;
            this.gridkhongthoihan.Visible = true;
            this.gridkhongthoihan.VisibleIndex = 4;
            this.gridkhongthoihan.Width = 83;
            // 
            // repositoryItemCheckEdit1
            // 
            this.repositoryItemCheckEdit1.AutoHeight = false;
            this.repositoryItemCheckEdit1.Name = "repositoryItemCheckEdit1";
            this.repositoryItemCheckEdit1.ValueChecked = "1";
            this.repositoryItemCheckEdit1.ValueUnchecked = "0";
            // 
            // gridngaycap
            // 
            this.gridngaycap.Caption = "Ngày cấp";
            this.gridngaycap.FieldName = "6";
            this.gridngaycap.Name = "gridngaycap";
            this.gridngaycap.OptionsColumn.AllowEdit = false;
            this.gridngaycap.OptionsColumn.ReadOnly = true;
            this.gridngaycap.Visible = true;
            this.gridngaycap.VisibleIndex = 5;
            this.gridngaycap.Width = 394;
            // 
            // gridsortdate
            // 
            this.gridsortdate.Caption = "sortdate";
            this.gridsortdate.FieldName = "8";
            this.gridsortdate.Name = "gridsortdate";
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Tahoma", 10F);
            this.label1.Location = new System.Drawing.Point(0, 630);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(60, 23);
            this.label1.TabIndex = 2;
            this.label1.Text = "Mã số:";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtmaso
            // 
            this.txtmaso.Location = new System.Drawing.Point(57, 632);
            this.txtmaso.Name = "txtmaso";
            this.txtmaso.Size = new System.Drawing.Size(120, 20);
            this.txtmaso.TabIndex = 3;
            // 
            // label2
            // 
            this.label2.Font = new System.Drawing.Font("Tahoma", 10F);
            this.label2.Location = new System.Drawing.Point(177, 631);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(100, 23);
            this.label2.TabIndex = 2;
            this.label2.Text = "Ngày sử dụng:";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // datengaysudung
            // 
            this.datengaysudung.EditValue = new System.DateTime(2013, 12, 27, 5, 36, 36, 460);
            this.datengaysudung.Location = new System.Drawing.Point(274, 632);
            this.datengaysudung.Name = "datengaysudung";
            this.datengaysudung.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
            this.datengaysudung.Properties.DisplayFormat.FormatString = "dd/MM/yyyy";
            this.datengaysudung.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.datengaysudung.Properties.EditFormat.FormatString = "dd/MM/yyyy";
            this.datengaysudung.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.datengaysudung.Properties.Mask.EditMask = "dd/MM/yyyy";
            this.datengaysudung.Properties.NullDate = new System.DateTime(2013, 12, 27, 5, 35, 7, 988);
            this.datengaysudung.Properties.VistaTimeProperties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton()});
            this.datengaysudung.Size = new System.Drawing.Size(94, 20);
            this.datengaysudung.TabIndex = 4;
            // 
            // numsongay
            // 
            this.numsongay.Location = new System.Drawing.Point(437, 633);
            this.numsongay.Maximum = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.numsongay.Minimum = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.numsongay.Name = "numsongay";
            this.numsongay.Size = new System.Drawing.Size(55, 21);
            this.numsongay.TabIndex = 5;
            this.numsongay.Value = new decimal(new int[] {
            1,
            0,
            0,
            0});
            // 
            // label3
            // 
            this.label3.Font = new System.Drawing.Font("Tahoma", 10F);
            this.label3.Location = new System.Drawing.Point(369, 631);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(68, 23);
            this.label3.TabIndex = 2;
            this.label3.Text = "Số ngày:";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // chkkhongthoihan
            // 
            this.chkkhongthoihan.AutoSize = true;
            this.chkkhongthoihan.Font = new System.Drawing.Font("Tahoma", 10F);
            this.chkkhongthoihan.Location = new System.Drawing.Point(498, 633);
            this.chkkhongthoihan.Name = "chkkhongthoihan";
            this.chkkhongthoihan.Size = new System.Drawing.Size(121, 21);
            this.chkkhongthoihan.TabIndex = 6;
            this.chkkhongthoihan.Text = "Không thời hạn";
            this.chkkhongthoihan.UseVisualStyleBackColor = true;
            this.chkkhongthoihan.CheckedChanged += new System.EventHandler(this.chkkhongthoihan_CheckedChanged);
            // 
            // label4
            // 
            this.label4.Font = new System.Drawing.Font("Tahoma", 10F);
            this.label4.Location = new System.Drawing.Point(620, 631);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(60, 23);
            this.label4.TabIndex = 2;
            this.label4.Text = "Keys:";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtkeys
            // 
            this.txtkeys.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.txtkeys.Location = new System.Drawing.Point(677, 633);
            this.txtkeys.Name = "txtkeys";
            this.txtkeys.Properties.ReadOnly = true;
            this.txtkeys.Size = new System.Drawing.Size(319, 20);
            this.txtkeys.TabIndex = 3;
            // 
            // btnketthuc
            // 
            this.btnketthuc.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnketthuc.Appearance.Options.UseTextOptions = true;
            this.btnketthuc.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
            this.btnketthuc.Location = new System.Drawing.Point(471, 665);
            this.btnketthuc.Name = "btnketthuc";
            this.btnketthuc.Size = new System.Drawing.Size(101, 23);
            this.btnketthuc.TabIndex = 38;
            this.btnketthuc.Text = " &Kết thúc [F12]";
            this.btnketthuc.Click += new System.EventHandler(this.btnketthuc_Click);
            // 
            // btnmoi
            // 
            this.btnmoi.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnmoi.Appearance.Options.UseTextOptions = true;
            this.btnmoi.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
            this.btnmoi.Location = new System.Drawing.Point(309, 665);
            this.btnmoi.Name = "btnmoi";
            this.btnmoi.Size = new System.Drawing.Size(75, 23);
            this.btnmoi.TabIndex = 36;
            this.btnmoi.Text = " &Mới";
            this.btnmoi.Click += new System.EventHandler(this.btnmoi_Click);
            // 
            // btnluu
            // 
            this.btnluu.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnluu.Appearance.Options.UseTextOptions = true;
            this.btnluu.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
            this.btnluu.Location = new System.Drawing.Point(390, 665);
            this.btnluu.Name = "btnluu";
            this.btnluu.Size = new System.Drawing.Size(75, 23);
            this.btnluu.TabIndex = 39;
            this.btnluu.Text = " &Tạo Key";
            this.btnluu.Click += new System.EventHandler(this.btnluu_Click);
            // 
            // frmcapkey
            // 
            this.ClientSize = new System.Drawing.Size(1008, 700);
            this.Controls.Add(this.btnluu);
            this.Controls.Add(this.btnketthuc);
            this.Controls.Add(this.btnmoi);
            this.Controls.Add(this.chkkhongthoihan);
            this.Controls.Add(this.numsongay);
            this.Controls.Add(this.datengaysudung);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtkeys);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txtmaso);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.gridControl);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmcapkey";
            this.Text = "Tạo key";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmcapkey_FormClosing);
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.gridControl)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.gridView1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.repositoryItemCheckEdit1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.txtmaso.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.datengaysudung.Properties.VistaTimeProperties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.datengaysudung.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.numsongay)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.txtkeys.Properties)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
    }
}

